//
//  ZMZSXiangQingLieBiaoViewController.m
//  ZhangMiZhuShou
//
//  Created by ryou on 2021/7/26.
//

#import "ZMZSXiangQingLieBiaoViewController.h"
#import "ZMZSXiangQingLieBiaoViewController.h"
#import "ZMZSXiangQingViewController.h"
#import "ZMZSXuanZeLeiXingViewController.h"

@interface ZMZSXiangQingLieBiaoViewController ()

@end

@implementation ZMZSXiangQingLieBiaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"分类详情";
    
    // Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
    
    for (UIView *view in self.view.subviews) {
        [view removeFromSuperview];
    }
    [self.ZMXZSData removeAllObjects];
    NSUserDefaults *ZMZSAcountMuser=[NSUserDefaults standardUserDefaults];
    NSArray *data=[ZMZSAcountMuser valueForKey:@"ZMZSaccountmanagermuserdata"];
    [self.ZMXZSData addObjectsFromArray:data];
    
    if (data.count==0) {
        [self zmxzsshowzmxzsAcountMnotData];
    }else{
        [self zmxzscreateView];
    }
}
-(void)zmxzsshowzmxzsAcountMnotData{
    UIImageView *zmxzsAcountMnotData=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pm_icon_zmxzsAcountMnotData.png"]];
    zmxzsAcountMnotData.center = self.view.center;
    [self.view addSubview:zmxzsAcountMnotData];
    
    UIButton *zmxzsAcountMsavebtn=[[UIButton alloc]initWithFrame:CGRectMake(kZMXZSWidth / 2 - 70, zmxzsAcountMnotData.frame.size.height+ zmxzsAcountMnotData.frame.origin.y + 30, 140, 60)];
    [zmxzsAcountMsavebtn setBackgroundImage:[UIImage imageNamed:@"zmxzs_icon_cellbg.png"] forState:UIControlStateNormal];
    [self.view addSubview:zmxzsAcountMsavebtn];
    zmxzsAcountMsavebtn.layer.cornerRadius = 30;
    zmxzsAcountMsavebtn.clipsToBounds=YES;
    [zmxzsAcountMsavebtn setTitle:@"添加账号" forState:UIControlStateNormal];
    [zmxzsAcountMsavebtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [zmxzsAcountMsavebtn addTarget:self action:@selector(zmxzspmzmxzscenterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)zmxzscreateView{
    UIImageView *bg=[[UIImageView alloc]initWithFrame:self.view.bounds];
    bg.image=[UIImage imageNamed:@"SH-2@3x.png"];
    bg.contentMode=UIViewContentModeScaleAspectFill;
    [self.view addSubview:bg];
    
    
    UIWindow * window = [[UIApplication sharedApplication].delegate window];
    CGFloat bottom = 0.0;
    if (@available(iOS 11.0, *)) {
        bottom = window.safeAreaInsets.top;
    } else {
        // Fallback on earlier versions
    }
    CGFloat yyy=self.navigationController.navigationBar.frame.origin.y +  self.navigationController.navigationBar.frame.size.height + bottom;
    [self createViewWith:yyy];
}
-(void)createViewWith:(CGFloat)yyy{
    CGFloat ZMZSitemW = 80;
    CGFloat ZMZSspace = (kZMXZSWidth - 80 * 3) / 4;
    
    for (int i=0; i<self.ZMXZSData.count; i++) {
        
        NSDictionary *dict = self.ZMXZSData[i];
        UIImageView *ZMZSZMZSAcountMbgimage=[[UIImageView alloc]initWithFrame:CGRectMake(ZMZSspace +(ZMZSitemW  + ZMZSspace) * (i%3),yyy + ZMZSspace +(ZMZSitemW  + ZMZSspace) * (i / 3), ZMZSitemW, ZMZSitemW)];
        ZMZSZMZSAcountMbgimage.image=[UIImage imageNamed:@"zmxzs_icon_bgfasdfad.png"];
        ZMZSZMZSAcountMbgimage.contentMode=UIViewContentModeScaleToFill;
        ZMZSZMZSAcountMbgimage.layer.cornerRadius=10;
        
        ZMZSZMZSAcountMbgimage.clipsToBounds=YES;
        [self.view addSubview:ZMZSZMZSAcountMbgimage];
        ZMZSZMZSAcountMbgimage.tag=i;
        ZMZSZMZSAcountMbgimage.userInteractionEnabled=YES;
        UITapGestureRecognizer *zmxzspmtap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bgClick:)];
        [ZMZSZMZSAcountMbgimage addGestureRecognizer:zmxzspmtap];
        
        
        UIImageView *icon=[[UIImageView alloc]initWithFrame:CGRectMake(20, 20, ZMZSZMZSAcountMbgimage.bounds.size.width - 40, ZMZSZMZSAcountMbgimage.bounds.size.height-40)];
        icon.image=[UIImage imageWithData:dict[@"ZMZSZMZSaccountmanagermuserpmbiaojipmicon"]];
        icon.contentMode=UIViewContentModeScaleAspectFill;
        icon.layer.cornerRadius=10;
        icon.clipsToBounds=YES;
        [ZMZSZMZSAcountMbgimage addSubview:icon];
        
    }
    
}
-(void)bgClick:(UITapGestureRecognizer *)sender{
    
    NSInteger tag = sender.view.tag;
    NSDictionary *dict = self.ZMXZSData[tag];
    ZMZSXiangQingViewController *detail=[[ZMZSXiangQingViewController alloc]init];
    detail.amDict=dict;
    [self.navigationController pushViewController:detail animated:YES];
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
-(void)zmxzspmzmxzscenterBtnClick{
    
    [self zmxzsaccountpmShowBUad];
    
}

-(void)zmxzsaccountpmShowBUad{
    
    ZMZSXuanZeLeiXingViewController *zmxzspmadd=[[ZMZSXuanZeLeiXingViewController alloc]init];
    [self.navigationController pushViewController:zmxzspmadd animated:YES];
    
}

@end

